/*
 * QE3e Qt Quick 3D Engine.
 * Copyright (C) 2010 Joris Vaillant and Mathieu Pujol
 * <joris.vaillant@gmail.com>  <mathieu.pujol87@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef QE3E_SCENE_H
#define QE3E_SCENE_H

// global
#include "qe3e_global.h"

// includes
// QE3e
#include "Flags.h"
// Qt4
#include <QVector>
#include <QSet>
#include <QVariant>

namespace qe3e
{
  // forward declaration
  class Item;
  class View;  

  class QE3E_EXPORT Scene
  {
  public:
    enum ItemUpdateType {PriorityChange
                         , OpacityChange};
  public:
    typedef QSet<Item*> ListItem;
    typedef ListItem::iterator ItemIterator;
    typedef ListItem::const_iterator ItemConstIterator;

    typedef QVector<View*> ListView;
    typedef ListView::iterator ViewIterator;
    typedef ListView::const_iterator ViewConstIterator;
  public:
    Scene();
    virtual ~Scene();

    void addRootItem(Item* item);
    void addItem(Item* item);
    void removeRootItem(Item* item);
    void removeItem(Item* item);

    bool itemExist(Item* item) const;

    ListItem& items();
    const ListItem& items() const;
    int itemsCount() const;

    ListItem& roots();
    const ListItem& roots() const;
    int rootsCount() const;

    void addView(View* view);
    void removeView(View* view);

    virtual void itemDirtyUpdate(Item* item, DirtyFlags flags);
    virtual void itemParentChange(Item* item, Item* oldParent, Item* newParent);
    virtual void itemPriorityChange(Item* item, double oldPrio, double newPrio);
    virtual void itemTransparencyChange(Item* item, bool oldTrans
                                        , bool newTrans);
    virtual void itemAdded(Item* item);
    virtual void itemRemoved(Item* item);
  protected:
    void addItemRec(Item* item);
    void removeItemRec(Item* item);

    void itemDirtyViewUpdate(Item* item, DirtyFlags flags);

  private:
    ListItem m_items;
    ListItem m_roots;
    ListView m_view;

  };
}

#endif //SCENE_H
